"""
@author LiuBoyuan
DESCRIPTION:
    SQLite 快速管理工具
"""
import Dao.DataBase


class SuperDBManager:
    @staticmethod
    def generate_dql_sql(myKvDouble: dict):
        """
        DESCRIPTION
            利用kv对生成dql条件语句
        @param myKvDouble: kv对 | 字典
        @return: sql语句
        """
        ResultString = ''
        for k, v in myKvDouble.items():
            ResultString += f"{k} = '{v}' and"
        ResultString = ResultString[0:-4]
        return ResultString

    @staticmethod
    def findByDict(UseDataBase: str, tableName: str, myKvDouble: dict):
        """
        DESCRIPTION
            利用字典生成SQL语句且查询
        @param UseDataBase: 链接 Database 目录加下的指定数据库名称
        @param tableName : 表名
        @param myKvDouble: kv对 | 字典
        @return: 查询数据
        """

        ResultString = SuperDBManager.generate_dql_sql(myKvDouble)
        return Dao.DataBase.sqlite_connect(UseDataBase).execute_DQL("select * from " + tableName + " where " +ResultString)


if __name__ == '__main__':
    print(SuperDBManager.findByDict(
        "UserInfo.db3",
        "UserInfo",
        {
            "用户名": "test"
        }
    ))
